﻿
@{
    bool? modelValue = null;
    if ( ViewData.Model != null ) 
    {
        modelValue = Convert.ToBoolean( ViewData.Model, System.Globalization.CultureInfo.InvariantCulture );
    }        
    
    IEnumerable<SelectListItem> triStateValues = null;
    
    if ( modelValue == null )
    {        
        triStateValues = new List<SelectListItem> 
        {
            new SelectListItem
            {
                Text = "Not Set",
                Value = "",
                Selected = !modelValue.HasValue
            },
            new SelectListItem
            {
                Text = "True",
                Value = "true",
                Selected = modelValue.HasValue && modelValue.Value   
            },
            new SelectListItem
            {
                Text = "False",
                Value = "false",
                Selected = modelValue.HasValue && !modelValue.Value
            }
        };      
    }    
}   


@if ( ViewData.ModelMetadata.IsNullableValueType ) {
    @Html.DropDownList( "", triStateValues, ViewData.ModelMetadata.MergeAttributes<HtmlAttributesAttribute>( new { @class = Html.GetProfile().DropDownClasses } ) )
} else {
    @Html.CheckBox( "", modelValue ?? false, ViewData.ModelMetadata.MergeAttributes<HtmlAttributesAttribute>( new { @class = Html.GetProfile().CheckBoxClasses } ) )
}